#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include "rngs.h"



#define DEBUG 0
#define NOISY_TEST 1

int smithyCard(struct gameState *state, int *currentPlayer, int *handPos);

int random_number(int min_num, int max_num)
{
    int result=0,low_num=0,hi_num=0;
    if(min_num<max_num)
    {
        low_num=min_num;
        hi_num=max_num+1;
    }
    else
    {
        low_num=max_num+1;
        hi_num=min_num;
    }
    
    srand(time(NULL));
    
    result = (rand()%(hi_num-low_num))+low_num;
    
    return result;
}

int main(int argc, char const *argv[]){
    
    struct gameState game;
    
    int i, j;
    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
    int card;
    
    int currentplayer;
    int handPos = -1;
    int holdingCards;
    
    
    // Loop for random test
    for (i = 0; i < random_number(0, 100); i ++)
    {
        initializeGame(random_number(2,4), k, random_number(1, 9), &game);
        
        // Run 1000x
        for (j = 0; j < 10000; j++)
        {
            currentplayer = game.whoseTurn;
            
            holdingCards = game.handCount[currentplayer];
            
            if(card = smithyCard(&game, &currentplayer, &handPos) != 0)
                printf("Error: smithyCard did not return a 0. Random Game[%d] iteration[%d]\n", i, j);
            if (holdingCards <= game.handCount[currentplayer])
            {
                game.outpostPlayed = 0;
            }
            
            game.phase = 0;
            game.numActions = 1;
            game.numBuys = 1;
            game.playedCardCount = 0;
            game.whoseTurn = random_number(2, game.numPlayers);
            game.handCount[game.whoseTurn] = 0;
        }
    }
    
    return 0;
}